<?php
require ("../database/categories.php");
?>
<?php 
  $error_name="";
  $error_infor="";
  $error_status="";
  $cate=new categories();
  if(isset($_POST['ok'])){
      if(trim($_POST['name']=="")){
          $error_name="Khong duoc de trong !";
         
      }else {
         if($cate->isExistName(trim($_POST['name'])))$error_name="Da ton tai!";
         else {
         if($cate->insert(trim($_POST['name']), trim($_POST['infor']), trim($_POST['status']))){
             echo'<span>Ban da them thanh cong </span></br>';
         }  else {
             echo '<span>Khong the them vao co so du lieu!</span></br>';
         }
            }
      }
  }
?>
<form method="post" action="">
<table>
    <tr>
        <td>Ten loai san pham :</td>
        <td><input type="text"size="30" name="name"> <span style="color: red">*<?php echo $error_name;?></span></td>
    </tr>
    <tr>
        <td>Thong tin: </td>
        <td><textarea rows="10" cols="30" name="infor"></textarea> <span><?php echo $error_infor;?></span></td>
    </tr>
    <tr>
        <td>Trang thai:</td>
        <td><input type="text" size="50" name="status"> <span><?php echo $error_status;?></span></td>
    </tr>
    <tr>
        <td></td>
        <td><input type="submit" name="ok" value="Them moi"></td>
    </tr>
</table>
</form>